#include "shell_port.h"
#include "bsp_shell.h"
#include "shell.h"
#include <stdio.h>

Shell shell;
char shellBuffer[512] = {0};


void vShellInit(void)
{
    shell.read = port_ShellRead;
    shell.write = port_ShellWrite;
    shellInit(&shell, shellBuffer, 512);
}



void vShellExec(char* str,uint32_t len)
{
    if (len < 3) {
        return;
    }
    if (str[len - 2] == 0x0d && str[len - 1] == 0x0a) {
        sprintf(shell.parser.buffer, str);
        shell.parser.length = len - 2;
        shellExec(&shell);
     }
}


/*****************************************************************************
* @brief  : shell进程
* @param  : None
* @retval :
* @author :
* @date   : 2023-05-23
* @note   :
*****************************************************************************/
void vShellProcess(void)
{
   int r=  port_ShellRead(shellBuffer, 128);
   if(r>0){
       vShellExec(shellBuffer,r);
   }
}


